//=============================================================================
// FunctionValue.as
// 
// 
// AUTHOR:             Jay Liang
// 
//                  Copyright (c) 2011 Break Media
//                              All Rights Reserved.
//                          
//=============================================================================
package values.other
{
import com.adobe.serialization.json.JSON;

import mx.utils.StringUtil;

public class FunctionValue
{    
	private static const XML_PATTERN:String = "<func name=\"{0}\" pri=\"{1}\" />";
	
    [Data(type="field", mapping="@name")]
    public var name:String;
	
	[Data(type="field", mapping="@pri")]
	public var pri:int = FunctionPRI.AFTER;
    
    [Data(type="field", mapping="@params")]
    public var paramString:String;
    
    public function get params():*
    {
        try
        {
            return JSON.decode(paramString);
        }
        catch (error:Error)
        {
            return paramString;
        }
    }
	
	public function clone():FunctionValue
	{
		var vo:FunctionValue = new FunctionValue();
		vo.name = name;
		vo.pri = pri;
		vo.paramString = paramString;
		return vo;
	}
	
	public function generateXML():XML
	{
		var xml:XML = new XML(StringUtil.substitute(XML_PATTERN, name, pri));
		if (paramString != null && paramString != "")
		{
			xml.@params = paramString;
		}
		return xml;
	}
}
}


